-
-
Save xNok/3082adbffcaead07642ab8c8912dfcd5 to your computer and use it in GitHub Desktop.
This file contains 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 Test_connectToInfluxDB(t *testing.T) { | |
//load environment variable from a file for test purposes | |
godotenv.Load("../test_influxdb.env") | |
tests := []struct { | |
name string | |
wantErr bool | |
}{ | |
{ | |
name: "Successful connection to InfluxDB", | |
wantErr: false, | |
}, | |
} | |
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
got, err := ConnectToInfluxDB() | |
if (err != nil) != tt.wantErr { | |
t.Errorf("ConnectToInfluxDB() error = %v, wantErr %v", err, tt.wantErr) | |
return | |
} | |
health, err := got.Health(context.Background()) | |
if (err != nil) && health.Status == domain.HealthCheckStatusPass { | |
t.Errorf("connectToInfluxDB() error. database not healthy") | |
return | |
} | |
got.Close() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment