add some backend unit tests
This commit is contained in:
		@@ -56,5 +56,5 @@ func (r *apicontext) Error(msg string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *apicontext) Errorf(msg string, args ...interface{}) {
 | 
			
		||||
	r.Error(fmt.Sprintf(msg, args))
 | 
			
		||||
	r.Error(fmt.Sprintf(msg, &args))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								apiGo/api/api/Hash_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								apiGo/api/api/Hash_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
package api
 | 
			
		||||
 | 
			
		||||
import "testing"
 | 
			
		||||
 | 
			
		||||
func TestHashlength(t *testing.T) {
 | 
			
		||||
	h := HashPassword("test")
 | 
			
		||||
 | 
			
		||||
	if len(*h) != 64 {
 | 
			
		||||
		t.Errorf("Invalid hash length: %d", len(*h))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								apiGo/api/api/Helpers_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								apiGo/api/api/Helpers_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
package api
 | 
			
		||||
 | 
			
		||||
import "testing"
 | 
			
		||||
 | 
			
		||||
func TestJsonify(t *testing.T) {
 | 
			
		||||
	var obj = struct {
 | 
			
		||||
		ID  uint32
 | 
			
		||||
		Str string
 | 
			
		||||
		Boo bool
 | 
			
		||||
	}{
 | 
			
		||||
		ID:  42,
 | 
			
		||||
		Str: "teststr",
 | 
			
		||||
		Boo: true,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	res := Jsonify(obj)
 | 
			
		||||
	exp := `{"ID":42,"Str":"teststr","Boo":true}`
 | 
			
		||||
 | 
			
		||||
	if string(res) != exp {
 | 
			
		||||
		t.Errorf("Invalid json response: %s !== %s", string(res), exp)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user