You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fabric/db/contexts_test.go

30 lines
717 B
Go

package db
import (
"os"
"path/filepath"
"testing"
)
func TestContexts_GetContext(t *testing.T) {
dir := t.TempDir()
contexts := &Contexts{
Storage: &Storage{Dir: dir},
}
contextName := "testContext"
contextPath := filepath.Join(dir, contextName)
contextContent := "test content"
err := os.WriteFile(contextPath, []byte(contextContent), 0644)
if err != nil {
t.Fatalf("failed to write context file: %v", err)
}
context, err := contexts.GetContext(contextName)
if err != nil {
t.Fatalf("failed to get context: %v", err)
}
expectedContext := &Context{Name: contextName, Content: contextContent}
if *context != *expectedContext {
t.Errorf("expected %v, got %v", expectedContext, context)
}
}