MCPcopy Index your code
hub / github.com/cheat/cheat / TestInit

Function TestInit

internal/config/init_test.go:11–39  ·  view source on GitHub ↗

TestInit asserts that configs are properly initialized

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// TestInit asserts that configs are properly initialized
11func TestInit(t *testing.T) {
12
13 // initialize a temporary config file
14 confFile, err := os.CreateTemp("", "cheat-test")
15 if err != nil {
16 t.Errorf("failed to create temp file: %v", err)
17 }
18
19 // clean up the temp file
20 defer os.Remove(confFile.Name())
21
22 // initialize the config file
23 conf := "mock config data"
24 if err = Init(confFile.Name(), conf); err != nil {
25 t.Errorf("failed to init config file: %v", err)
26 }
27
28 // read back the config file contents
29 bytes, err := os.ReadFile(confFile.Name())
30 if err != nil {
31 t.Errorf("failed to read config file: %v", err)
32 }
33
34 // assert that the contents were written correctly
35 got := string(bytes)
36 if got != conf {
37 t.Errorf("failed to write configs: want: %s, got: %s", conf, got)
38 }
39}
40
41// TestInitCreateDirectory tests that Init creates the directory if it doesn't exist
42func TestInitCreateDirectory(t *testing.T) {

Callers

nothing calls this directly

Calls 1

InitFunction · 0.85

Tested by

no test coverage detected