github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/lib/setup_test.go (about)

     1  package lib
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	testcfg "github.com/qri-io/qri/config/test"
     9  	regmock "github.com/qri-io/qri/registry/regserver"
    10  	repotest "github.com/qri-io/qri/repo/test"
    11  )
    12  
    13  func TestSetupTeardown(t *testing.T) {
    14  	reg := regmock.NewMemRegistry(nil)
    15  	_, registryServer := regmock.NewMockServerRegistry(reg)
    16  
    17  	path := filepath.Join(os.TempDir(), "test_lib_setup_teardown")
    18  	cfg1 := testcfg.DefaultConfigForTesting()
    19  	cfg1.Repo.Type = "mem"
    20  	params := SetupParams{
    21  		RepoPath:            path,
    22  		Config:              testcfg.DefaultConfigForTesting(),
    23  		Generator:           repotest.NewTestCrypto(),
    24  		SetupIPFS:           true,
    25  		SetupIPFSConfigData: ipfsCfg,
    26  		InitIPFSFunc:        repotest.InitIPFSRepo,
    27  		Register:            true,
    28  	}
    29  	params.Config.Profile.Peername = "hallo"
    30  	params.Config.Registry.Location = registryServer.URL
    31  	if err := Setup(params); err != nil {
    32  		t.Error(err.Error())
    33  	}
    34  
    35  	// TODO (b5) - registry flow is now different, we should implement a new
    36  	// command "qri registry auth" that mimics what qri desktop is doing on
    37  	// the command line
    38  	// length, err := reg.Profiles.Len()
    39  	// if err != nil {
    40  	// 	t.Fatal(err)
    41  	// }
    42  	// if length != 1 {
    43  	// 	t.Errorf("expected registry to have one profile. got: %d", length)
    44  	// }
    45  	// reg.Profiles.SortedRange(func(key string, profile *registry.Profile) (bool, error) {
    46  	// 	if profile.Username != params.Config.Profile.Peername {
    47  	// 		t.Errorf("username mismatch. profile.Username: %s, config.Peername: %s", profile.Username, params.Config.Profile.Peername)
    48  	// 	}
    49  	// 	return true, nil
    50  	// })
    51  
    52  	err := Teardown(TeardownParams{
    53  		Config:   params.Config,
    54  		RepoPath: path,
    55  	})
    56  
    57  	if err != nil {
    58  		t.Error(err.Error())
    59  	}
    60  
    61  }
    62  
    63  var ipfsCfg = []byte(`{
    64    "Identity": {
    65      "PeerID": "QmUiF6GyKcNt3fbc9pCN72KF5qgneLt3eufVT3tGEBiR9h",
    66      "PrivKey": "CAASqQkwggSlAgEAAoIBAQD8vTnrl8vClngB1zSSOvlL15tKwXabTdFMTsIXFE1j9TxdksgKinBhT/fvbbt3W4Il8kmhz37ShlUQ8alkr2Uf7/cW6VPD8BdISfzEXc8th5rl0mDxJtKvPkYYbRcBZwUH2fL1KLaaRRYEVq0BItHpldtfaajtD04H+kYFPSdapxuPLNDPBxyaVoX2Yiqi/PmYuK6RJA1od27SqPicVMC7QXKZxNpz3Y2Q8g1+PAc+2uIbbWQ3Ow2a7E37+/Rt2NzlcB7R/n1Lpj0YhwRmNCxuyEmwkgd0VHFIjyrRwoRhFBA88o5Go2nNRb0tc9Iq1eFDpU+HXLx5uZYBKe/JZXIXAgMBAAECggEBAMZj8zdP7I5Odt1bBNVUnaQ/FpNT0bqPFyADIq/jK+yu8DezpHtBuH1qvIChbmp+1mbbDZmKu06eS+AFEqcKVyL+xsKhXTONH3mLOnMaACsJKzoELjyd8PvGslcyKsDbEUPcfa6bytrGKEY3k440uvnUvGLlGckcHnB8sMIkAuRQgSbRXSRmfvnyy/VW7+l4ivy0t5528M4yG6i+xbgJqYO14SAblIV/c66mYfLXd1enW2bijZEtMkS1537EuU5hy/HQoCJ8OGHx9R4DRzIyhJTonmv1Xh97+dvF3c/ibNjkIQyN3z2heivVCLoRTMlD5QIS4p6PCaahPb4s+NgA9YECgYEA/tYaDt1fTLA44J9SeUVisXk7cQ1Hi4y3IyhrtRQ8M53Z3pKIWbw68Qv4ZRqRoPK8NOclb4A/mKnyi52rIu7TL7Dn/p0KS4fazcclAaGae59z7qAlg+RadBruS1kPHAYCrbh5YWfyNgeuUHxAYrMimKAeT5jwrdW4pTQj7cRJp2cCgYEA/eSsRCeUkSbCCG1cTS5YeRp0Zpp1+sGuSsZkmp9eOzz6J9Bk6Df70gOU4AShpn7smZYlGYpmoPtdgLziSORDoTRPWL3rXLWXNVqyTVheGcrdYtMEf8vNCVduOfOYDekBsJ8xABDelkGGXPOiWkF+yFchx1V2d27SmX/1CJ+kodECgYEA05PXFrhdQ0KcNoKQ6vbcthS9cWNhH0+5TYtlwXYHdaN9G/n1Euvg0/joRqkEd+iQsiunPSfxpUKUia5iRCKdXF84foDL52HoHClXZD9UD4eXrWtxOkwBfZxOdGiAzvd+idU7kc/HnWxLIa/HlSq9cpKeF+AXE3z6TM85dVMfA8kCgYEAz/5a5carHjJrOK4mtI/oKOX0P+4AAvpSR6250zYF42+z25QMZnUellEa0F7a8uP9/mCTahYIt47VbdbPZjmh8dlBu4hy3VNiWXJAqb5f8K9RqFkI0YzrHuECSvV1NsgQ+1mesdggEWYCpfltopUPQR6obH1l/LfMTbYWzgbCv1ECgYBFZYJahdVLmSpZvESJ3UbxkoWEgSGfw8u67NvYSeYAvCLtb9T02HBvYk4AdKYVRBu2rclf1I8mr8pGoBq2eb11A5i9gWw+8YcvkRFv6qJcgcuQKUAGqw95xDd4C0OuQxQMdx3LxIzPHz7OvSO67YhzuafN5aaalt9WQKyfitrubQ=="
    67    },
    68    "Datastore": {
    69      "StorageMax": "10GB",
    70      "StorageGCWatermark": 90,
    71      "GCPeriod": "1h",
    72      "Spec": {
    73        "mounts": [
    74          {
    75            "child": {
    76              "path": "blocks",
    77              "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
    78              "sync": true,
    79              "type": "flatfs"
    80            },
    81            "mountpoint": "/blocks",
    82            "prefix": "flatfs.datastore",
    83            "type": "measure"
    84          },
    85          {
    86            "child": {
    87              "compression": "none",
    88              "path": "datastore",
    89              "type": "levelds"
    90            },
    91            "mountpoint": "/",
    92            "prefix": "leveldb.datastore",
    93            "type": "measure"
    94          }
    95        ],
    96        "type": "mount"
    97      },
    98      "HashOnRead": false,
    99      "BloomFilterSize": 0
   100    },
   101    "Addresses": {
   102      "Swarm": [
   103        "/ip4/0.0.0.0/tcp/4001",
   104        "/ip6/::/tcp/4001"
   105      ],
   106      "Announce": [],
   107      "NoAnnounce": [],
   108      "API": "/ip4/127.0.0.1/tcp/5001",
   109      "Gateway": "/ip4/127.0.0.1/tcp/8080"
   110    },
   111    "Mounts": {
   112      "IPFS": "/ipfs",
   113      "IPNS": "/ipns",
   114      "FuseAllowOther": false
   115    },
   116    "Discovery": {
   117      "MDNS": {
   118        "Enabled": true,
   119        "Interval": 10
   120      }
   121    },
   122    "Ipns": {
   123      "RepublishPeriod": "",
   124      "RecordLifetime": "",
   125      "ResolveCacheSize": 128
   126    },
   127    "Bootstrap": [
   128      "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
   129      "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
   130      "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
   131      "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
   132      "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
   133      "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
   134      "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
   135      "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
   136      "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
   137      "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
   138      "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
   139      "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
   140      "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"
   141    ],
   142    "Gateway": {
   143      "HTTPHeaders": {
   144        "Access-Control-Allow-Headers": [
   145          "X-Requested-With",
   146          "Range"
   147        ],
   148        "Access-Control-Allow-Methods": [
   149          "GET"
   150        ],
   151        "Access-Control-Allow-Origin": [
   152          "*"
   153        ]
   154      },
   155      "RootRedirect": "",
   156      "Writable": false,
   157      "PathPrefixes": []
   158    },
   159    "API": {
   160      "HTTPHeaders": null
   161    },
   162    "Swarm": {
   163      "AddrFilters": null,
   164      "DisableBandwidthMetrics": false,
   165      "DisableNatPortMap": false,
   166      "DisableRelay": false,
   167      "EnableRelayHop": false,
   168      "ConnMgr": {
   169        "Type": "basic",
   170        "LowWater": 600,
   171        "HighWater": 900,
   172        "GracePeriod": "20s"
   173      }
   174    },
   175    "Reprovider": {
   176      "Interval": "12h",
   177      "Strategy": "all"
   178    },
   179    "Experimental": {
   180      "FilestoreEnabled": false,
   181      "ShardingEnabled": false,
   182      "Libp2pStreamMounting": false
   183    }
   184  }`)