47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package mock
 | 
						|
 | 
						|
import "testing"
 | 
						|
 | 
						|
func TestConfig(test *testing.T) {
 | 
						|
	config := Config {
 | 
						|
		"single": []string { "aslkdjasd" },
 | 
						|
		"multiple": []string { "item0", "item1" },
 | 
						|
		"empty": []string { },
 | 
						|
	}
 | 
						|
	if correct, got := "aslkdjasd", config.Get("single"); correct != got {
 | 
						|
		test.Fatal("not equal:", got)
 | 
						|
	}
 | 
						|
	if correct, got := "item0", config.Get("multiple"); correct != got {
 | 
						|
		test.Fatal("not equal:", got)
 | 
						|
	}
 | 
						|
	if correct, got := "", config.Get("empty"); correct != got {
 | 
						|
		test.Fatal("not equal:", got)
 | 
						|
	}
 | 
						|
	if correct, got := "", config.Get("non-existent"); correct != got {
 | 
						|
		test.Fatal("not equal:", got)
 | 
						|
	}
 | 
						|
	for index, value := range config.GetAll("single") {
 | 
						|
		if index < 0 { test.Fatal("index too small") }
 | 
						|
		if index > 0 { test.Fatal("index too large") }
 | 
						|
		if value != "aslkdjasd" {
 | 
						|
			test.Fatal("not equal:", value)
 | 
						|
		}
 | 
						|
	}
 | 
						|
	for index, value := range config.GetAll("multiple") {
 | 
						|
		if index < 0 { test.Fatal("index too small") }
 | 
						|
		if index > 1 { test.Fatal("index too large") }
 | 
						|
		switch value {
 | 
						|
		case "item0": if index != 0 { test.Fatal("not equal:", index, value) }
 | 
						|
		case "item1": if index != 1 { test.Fatal("not equal:", index, value) }
 | 
						|
		default:
 | 
						|
			test.Fatal("should not have value:", index, value)
 | 
						|
		}
 | 
						|
	}
 | 
						|
	for index, value := range config.GetAll("empty") {
 | 
						|
		test.Fatal("should not have value:", index, value)
 | 
						|
	}
 | 
						|
	for index, value := range config.GetAll("non-existent") {
 | 
						|
		test.Fatal("should not have value:", index, value)
 | 
						|
	}
 | 
						|
}
 |