github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/manifest/download_test.go (about) 1 // Copyright 2021 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 5 package manifest 6 7 import ( 8 "fmt" 9 "net/http" 10 "net/http/httptest" 11 "testing" 12 ) 13 14 var manifestJSONSource = ` 15 { 16 "version": "2", 17 "chain": "mainnet", 18 "specification": "QmUou7zX2g2tY58LP1A2GyP5RF9nbJsoxKTp299ah3svgb", 19 "chunks": [ 20 { 21 "fileName": "000000000-000000000", 22 "bloomHash": "QmPQEgUm7nzQuW9HYyWp5Ff3aoUwg2rsxDngyuyddJTvrv", 23 "indexHash": "QmZ5Atm8Z7aFLz2EycK4pVMHuH4y3PDGspuFejnE9fx2i5" 24 }, 25 { 26 "fileName": "000000001-000350277", 27 "bloomHash": "QmZgrWAJLidkHJRLDVoZGCWAgmmcQEDCDM65XL5ZbAXxCM", 28 "indexHash": "QmP1KvDPUJ1MqsCYcicJgTf5sxN7WjT7dZsrfBk2Jg3mSe" 29 } 30 ] 31 } 32 ` 33 34 func TestDownloadJSON(t *testing.T) { 35 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 36 w.Header().Set("Content-Type", "application/json") 37 fmt.Fprintln(w, manifestJSONSource) 38 })) 39 40 defer ts.Close() 41 42 manifest, err := downloadManifest("mainnet", ts.URL, "") 43 if err != nil { 44 t.Error(err) 45 } 46 47 if l := len(manifest.Chunks); l != 2 { 48 t.Errorf("Wrong NewPins length: %d", l) 49 } 50 }