| package features | |
| import ( | |
| "os" | |
| "reflect" | |
| "testing" | |
| ) | |
| func TestReadCOSGPUConfigFileExists(t *testing.T) { | |
| tmpFile, err := os.CreateTemp("", "cos-gpu-config") | |
| if err != nil { | |
| t.Fatalf("Failed to create temp file: %v", err) | |
| } | |
| defer os.Remove(tmpFile.Name()) | |
| _, err = tmpFile.WriteString(`{"use-proto": true}`) | |
| if err != nil { | |
| t.Fatalf("Failed to write to tmp file: %v", err) | |
| } | |
| tmpFile.Close() | |
| gpuConfig, err := ReadCOSGPUConfig(tmpFile.Name()) | |
| if err != nil { | |
| t.Fatalf("Read cos gpu config failed: %v", err) | |
| } | |
| var expectedGPUConfig = &GPUConfig{UseProto: true} | |
| if !reflect.DeepEqual(gpuConfig, expectedGPUConfig) { | |
| t.Errorf("Expected result: %+v, got result: %+v", expectedGPUConfig, gpuConfig) | |
| } | |
| } | |
| func TestReadCOSGPUConfigFileNotExists(t *testing.T) { | |
| gpuConfig, err := ReadCOSGPUConfig("not-exist-config-file.json") | |
| if err != nil { | |
| t.Errorf("Expected no error when reding not exist config file, but we got: %v", err) | |
| } | |
| var expectedDefaultGPUConfig = &GPUConfig{UseProto: false} | |
| if !reflect.DeepEqual(gpuConfig, expectedDefaultGPUConfig) { | |
| t.Errorf("Expected result: %+v, got result: %+v", expectedDefaultGPUConfig, gpuConfig) | |
| } | |
| } |