From 538e305925b9b04102ef0a4fb7cca19a6c116142 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Sat, 20 Jun 2020 02:27:31 -0400 Subject: updating module to live at sourcehut Also moving the 'registry' library into this repo, rather than maintaining them separately. It will still be decoupled, just live in this repository. --- registry/init_test.go | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 registry/init_test.go (limited to 'registry/init_test.go') diff --git a/registry/init_test.go b/registry/init_test.go new file mode 100644 index 0000000..ab9d494 --- /dev/null +++ b/registry/init_test.go @@ -0,0 +1,93 @@ +/* +Copyright (c) 2019 Ben Morrison (gbmor) + +This file is part of Registry. + +Registry is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Registry is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Registry. If not, see . +*/ + +package registry //import "git.sr.ht/~gbmor/getwtxt/registry" + +import ( + "fmt" + "log" + "os" + "time" +) + +func quickErr(err error) { + if err != nil { + fmt.Printf("%v\n", err) + } +} + +// Sets up mock users and statuses +func initTestEnv() *Registry { + hush, err := os.Open("/dev/null") + quickErr(err) + log.SetOutput(hush) + + // this is a bit tedious, but set up fake dates + // for the mock users' join and status timestamps + timeMonthPrev := time.Now().AddDate(0, -1, 0) + timeMonthPrevRFC := timeMonthPrev.Format(time.RFC3339) + + timeTwoMonthsPrev := time.Now().AddDate(0, -2, 0) + timeTwoMonthsPrevRFC := timeTwoMonthsPrev.Format(time.RFC3339) + + timeThreeMonthsPrev := time.Now().AddDate(0, -3, 0) + timeThreeMonthsPrevRFC := timeThreeMonthsPrev.Format(time.RFC3339) + + timeFourMonthsPrev := time.Now().AddDate(0, -4, 0) + timeFourMonthsPrevRFC := timeFourMonthsPrev.Format(time.RFC3339) + + var mockusers = []struct { + url string + nick string + date string + apidate []byte + status TimeMap + }{ + { + url: "https://example3.com/twtxt.txt", + nick: "foo_barrington", + date: timeTwoMonthsPrevRFC, + status: TimeMap{ + timeTwoMonthsPrev: "foo_barrington\thttps://example3.com/twtxt.txt\t" + timeTwoMonthsPrevRFC + "\tJust got started with #twtxt!", + timeMonthPrev: "foo_barrington\thttps://example3.com/twtxt.txt\t" + timeMonthPrevRFC + "\tHey <@foo https://example.com/twtxt.txt>, I love programming. Just FYI.", + }, + }, + { + url: "https://example.com/twtxt.txt", + nick: "foo", + date: timeFourMonthsPrevRFC, + status: TimeMap{ + timeFourMonthsPrev: "foo\thttps://example.com/twtxt.txt\t" + timeFourMonthsPrevRFC + "\tThis is so much better than #twitter", + timeThreeMonthsPrev: "foo\thttps://example.com/twtxt.txt\t" + timeThreeMonthsPrevRFC + "\tI can't wait to start on my next programming #project with <@foo_barrington https://example3.com/twtxt.txt>", + }, + }, + } + registry := New(nil) + + // fill the test registry with the mock users + for _, e := range mockusers { + data := &User{} + data.Nick = e.nick + data.Date = e.date + data.Status = e.status + registry.Users[e.url] = data + } + + return registry +} -- cgit 1.4.1-2-gfad0