github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/shared/metrics/models_test.go (about) 1 // +build small 2 3 // Copyright 2017 The WPT Dashboard Project. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 package metrics 8 9 import ( 10 "encoding/json" 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 "github.com/web-platform-tests/wpt.fyi/shared" 15 ) 16 17 func TestTestRunsLegacy_Convert(t *testing.T) { 18 run := TestRunLegacy{ 19 ID: 123, 20 ProductAtRevision: shared.ProductAtRevision{ 21 Product: shared.Product{ 22 BrowserName: "chrome", 23 }, 24 Revision: "1234512345", 25 }, 26 } 27 meta := TestRunsMetadataLegacy{ 28 TestRunIDs: shared.TestRunIDs{ 29 123, 30 }, 31 TestRuns: []TestRunLegacy{ 32 run, 33 }, 34 } 35 bytes, _ := json.Marshal(meta) 36 var metaNew TestRunsMetadata 37 json.Unmarshal(bytes, &metaNew) 38 assert.Equal(t, meta.TestRunIDs, metaNew.TestRuns.GetTestRunIDs()) 39 converted, err := ConvertRuns(metaNew.TestRuns) 40 assert.Nil(t, err) 41 assert.Equal(t, meta.TestRuns, converted) 42 } 43 44 func TestGetDatastoreKindName(t *testing.T) { 45 var m PassRateMetadata 46 assert.Equal(t, "github.com.web-platform-tests.results-analysis.metrics.PassRateMetadata", GetDatastoreKindName(m)) 47 }