Ready for first test?
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								example/example
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								example/example
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										54
									
								
								example/example.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								example/example.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
    "gitto.work/shortcut/scsusers"
 | 
			
		||||
    "github.com/jmoiron/sqlx"
 | 
			
		||||
    "flag"
 | 
			
		||||
    "os"
 | 
			
		||||
    "fmt"
 | 
			
		||||
_    "github.com/mattn/go-sqlite3"
 | 
			
		||||
    )
 | 
			
		||||
    
 | 
			
		||||
func main() {
 | 
			
		||||
    var email string
 | 
			
		||||
    
 | 
			
		||||
    flag.StringVar(&email, "email", "", "Email address to use for registration test")
 | 
			
		||||
    flag.Parse()
 | 
			
		||||
 | 
			
		||||
    db, err:=sqlx.Open("sqlite3", ":memory")
 | 
			
		||||
    if err!=nil {
 | 
			
		||||
        fmt.Println("Couldn't open sqlite3 in-memory db:" + err.Error())
 | 
			
		||||
        os.Exit(1)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err=db.Ping()
 | 
			
		||||
    if err!=nil {
 | 
			
		||||
        fmt.Println("Couldn't ping sqlite3 in-memory db:" + err.Error())
 | 
			
		||||
        os.Exit(1)
 | 
			
		||||
    }
 | 
			
		||||
    schema:=`CREATE TABLE test_auth (
 | 
			
		||||
        username text NOT NULL unique key ,
 | 
			
		||||
        crypt text NOT NULL, 
 | 
			
		||||
        email text NOT NULL unique key, 
 | 
			
		||||
        recovery text NOT NULL DEFAULT '',
 | 
			
		||||
        recoverytime timestamp null,
 | 
			
		||||
        lastseen timestamp );`
 | 
			
		||||
    _ ,err=db.Exec(schema)
 | 
			
		||||
    if err != nil {
 | 
			
		||||
        fmt.Println("Schema creation failed: " + err.Error())
 | 
			
		||||
        os.Exit(1)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    scsusers.Init(db, "test", "Example Test", "nobody@nowhere.com")
 | 
			
		||||
    a:=scsusers.UsernameAvailable("testuser")
 | 
			
		||||
    fmt.Printf("Initial test of username available: %v\n", a)
 | 
			
		||||
    a=scsusers.Register("testuser", email, "127.0.0.1")
 | 
			
		||||
    fmt.Printf("Register returned %v\n",a)
 | 
			
		||||
    fmt.Printf("Enter code from email:")
 | 
			
		||||
    var code string
 | 
			
		||||
    fmt.Scan(&code)
 | 
			
		||||
    a=scsusers.Login("testuser", code)
 | 
			
		||||
    fmt.Printf("Login returned %v\n",a)
 | 
			
		||||
    
 | 
			
		||||
     
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user