Created
February 14, 2021 19:02
-
-
Save madflojo/2465d376a1a94cccf225e0faf8b43308 to your computer and use it in GitHub Desktop.
Interface Article - MockDB Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestIsOver9k(t *testing.T) { | |
t.Run("TestOver9000", func(t *testing.T) { | |
DB = &MockDB{ | |
FakeFetch: func(string) (int, error) { | |
return 9001, nil | |
}, | |
} | |
if !isOver9000() { | |
t.Errorf("Test did not return expected results") | |
} | |
}) | |
t.Run("TestUnder9000", func(t *testing.T) { | |
DB = &MockDB{ | |
FakeFetch: func(string) (int, error) { | |
return 8999, nil | |
}, | |
} | |
if isOver9000() { | |
t.Errorf("Test did not return expected results") | |
} | |
}) | |
t.Run("TestDBError", func(t *testing.T) { | |
DB = &MockDB{ | |
FakeFetch: func(string) (int, error) { | |
return 0, fmt.Errorf("unable to connect to database") | |
}, | |
} | |
if isOver9000() { | |
t.Errorf("Test did not return expected results") | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment